import axios from '@/utils/http.jsx'
import { message } from 'antd';
const Http = async (url, method, params) => {
    let result = {}
    if (method == 'get') {
        await axios({
            url,
            method,
            params
        }).then((res) => {
            if (res.code === 200) {
                result.data = res.data
                result.msg = res.msg
                result.code = res.code
            }
            else {
                message.error(res.msg);
                result.data = [] 
            }
        }).catch((err)=>{
            message.error('后台服务器连接失败,请稍后重试！')
        })
    }
    else if (method == 'post') {
        await axios({
            url,
            method,
            data: params
        }).then((res) => {
            if (res.code === 200) {
                result.data = res.data
                result.msg = res.msg
                result.code = res.code
            } else {
                message.error(res.msg);
                result.data = []
            }
        }).catch((err) => {
            message.error('后台服务器连接失败,请稍后重试！')
        })
    }

    return result
}

export { Http }